package com.wjy.simple.activity;

import android.content.SharedPreferences;
import android.os.Bundle;

import com.wjy.sfhcore.util.ToastUtil;
import com.wjy.simple.R;
import com.wjy.simple.fragment.MainFragment;
import com.wjy.simple.util.SPHelper;

/**
 * Created by lawrence on 15/7/31.
 */
public class MainActivity extends BaseActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ToastUtil.toast(SPHelper.getInstance().getString());
        SPHelper.getInstance().registerOnSharedPreferenceChangeListener(this);
        SPHelper.getInstance().saveString("haha");
    }

    @Override
    protected void onDestroy() {
        SPHelper.getInstance().unregisterOnSharedPreferenceChangeListener(this);
        super.onDestroy();
    }

    @Override
    public void addContainer() {
        replaceFragment(R.id.activity_container, new MainFragment(), false);
    }

    @Override
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
        ToastUtil.toast(SPHelper.getInstance().getString());
    }
}
